package com.atguigu.spzx.manager.controller;

import cn.hutool.http.server.HttpServerRequest;
import cn.hutool.http.server.HttpServerResponse;
import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "种类管理")
@RestController
@RequestMapping("/admin/product/category")
@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @Operation(summary = "查询种类")
    @GetMapping("/findByParentId/{parentId}")
    public Result<List<Category>> findByParentId(@PathVariable Long parentId){
        List<Category> list=categoryService.findByParentId(parentId);
        return Result.ok(list);
    }

    @Operation(summary = "导出")
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){//导出数据：将数据库数据写入内存Excel中，以流的形式将文件返回给客户端。注意：不是Result
        categoryService.exportData(response);
    }

    @Operation(summary = "导入")
    @PostMapping("/importData")
    public Result importData(MultipartFile file){
        categoryService.importData(file);
        return Result.ok(null);
    }
}
